<?php
/**
 * @brief 商品模块
 * @class Goods
 * @note  后台
 */
class Test extends IController{
 

 function add(){
 	 // echo "11";
 	$this->redirect("add");
 }

	function add_do(){
		$pwd=IReq::get("pwd");
		$name=IReq::get("name");
		$data=new IModel("test");
		$arr=array(
	           "name"=>$name,
	           "pwd"=>$pwd
			);
		$data->setData($arr);
		$res=$data->add();
		if($res){
			$this->redirect("show");
		}
	}

	function show()
	{
	    	$data=new IModel("test");
	    	$res=$data->query();
	    	// var_dump($res);die;
	    	$this->setRenderData(['res'=>$res]);
	    	$this->redirect("show");
	}

	function up_show()
		{
			$id=IReq::get("id");
			// echo $id;
			$data=new IModel("test");
	    	$res=$data->query("id=$id");
	    	// var_dump($res);die;
	    	$this->setRenderData(['res'=>$res]);
	    	$this->redirect("up_show");

		}

		function updo(){
			$id=IReq::get("id");
			$name=IReq::get("name");
			// echo $name;die;
			$pwd=IReq::get("pwd");
			$data=new IModel("test");
			$arr=array(
                 "name"=>$name,
                 "pwd"=>$pwd
				);
			$data->setData($arr);
			$res=$data->update("id=$id");
		   if($res){
		   	   echo '成功';
		    	$this->redirect("show");
		   }
		}
			function del()
			{
				$id=IReq::get("id");
				// echo $id;die;
				$data=new IModel("test");
		    	$res=$data->del("id=$id");
		    	// var_dump($res);die;
		    	if($res){
		    		$this->redirect("show");
		    	}


			}


			function dt(){

				 $this->redirect("dt");
			}
            //经度纬度查询位置
			function dtss(){
				$address=$_POST['addr'];
				$ak="fZAQ5GXps6eyzh88eCoOjH1kDUMwe06u";
				
				$url="http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
                $data=file_get_contents($url);
                $data=json_decode($data,true);
                $lng=$data['result']['location']['lng'];
                $lat=$data['result']['location']['lat'];
                $arr=array(
                       "lng"=>$lng,
                       "lat"=>$lat
                	 );
                   echo json_encode($arr);

			}
			//发邮件
			function do_email(){
				$addr=IReq::get("addr");
				$mail=new SendMail();
				$title="您好，这是个测试";
				$content="我奥中国";
				$mail->send($addr,$title,$content);
			}


			//qq登陆
			function qq_login(){

                  $appid='101353491';
                  $redirect_uri="http://www.shop.com/index.php";
                  $state=rand(1000,9999);
				  $url="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&state=$state";
                  header("location:$url");
			}
}